package entity

import (
	"html"
	"strings"
	"time"
)

type Folder struct {
	ID              uint64    `gorm:"primary_key;auto_increment" json:"id"`
	ParentID        uint64    `gorm:"size:100;;not null" json:"parent_id"`
	Name            string    `gorm:"type:varchar(255)"`
	InnerCode       string    `gorm:"type:varchar(255)"`
	BranchInnerCode string    `gorm:"type:varchar(255)"`
	Type            string    `gorm:"size:50;null;" json:"filename"`
	TreeLevel       uint64    `gorm:"size:100;;not null" json:"level"`
	ChildCount      uint64    `gorm:"size:100;;not null" json:"child_count"`
	IsLeaf          uint64    `gorm:"size:100;;not null" json:"is_leaf"`
	ConfigProps     string    `gorm:"size:500;null;" json:"path"`
	AddUser         string    `gorm:"size:50;null" json:"adduser"`
	AddTime         time.Time `gorm:"default:CURRENT_TIMESTAMP"`
}

func (Folder) TableName() string {
	return "zecatalog"
}

func (f *Folder) BeforSave() {
	f.Name = html.EscapeString(strings.TrimSpace(f.Name))
}
